<?php
	require_once dirname(BASEPATH) . '/application/models/local/data/cafe/_init_model_cafe.php';
	
	class mod_cafe_type_list extends _init_model_cafe
	{
		public $CAF_T_L_ID;
		public $CAF_T_L_LIST;
		public $CAF_ID;
		
		function __construct(){
			parent::__construct();
				
			$this->tableName = 'cafe_type_list';
		}
		
		function add(){			
			$this->db->where('CAF_ID', $this->CAF_ID);
			$count = $this->db->count_all_results($this->tableName);				
				
			if ($count <= 0)								
				return $this->db->insert($this->tableName, array('CAF_T_L_LIST' => $this->CAF_T_L_LIST,
																	'CAF_ID' => $this->CAF_ID));			
			else
				return $this->update($this->CAF_ID);			
		}
		function update($cafe_id){			
			$this->db->where('CAF_ID', $cafe_id);
			return $this->db->update($this->tableName, array('CAF_T_L_LIST' => $this->CAF_T_L_LIST,
																'CAF_ID' => $this->CAF_ID));
		}
		function get_typelist_of_cafe($cafe_id, $show_title=false){
			$this->db->select('CAF_T_L_LIST');
			$this->db->where('CAF_ID', $cafe_id);
			$query = $this->db->get($this->tableName);
						
			$return = array();
			if ($query->num_rows() > 0)
				$return = explode(',', $query->row(0)->CAF_T_L_LIST);
			if ($show_title){
				$this->load->model('local/data/cafe/mod_cafe_type');
				for ($i=0; $i<count($return); $i++){
					$return[$i] = $this->mod_cafe_type->get_cafe_type_title($return[$i]);
				}
			}
			
			return $return;
		}		
	}
?>